#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time         : 17-12-13 下午4:11
# @Author       : xiaohan
# @File         : signals.py
# @desc         :
from django.contrib.auth import get_user_model
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token

User = get_user_model()


# 这里写完要在apps里面做设置
@receiver(post_save, sender=User)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        password = instance.password
        instance.set_password(password)
        instance.save()
        # Token.objects.create(user=instance)
